package com.god530.listdemo;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.god530.listdemo.customview.CustomViewActivity;
import com.god530.listdemo.customview2.CustomViewActivity2;
import com.joanzapata.android.BaseAdapterHelper;
import com.joanzapata.android.QuickAdapter;

public class MainActivity extends Activity implements OnItemClickListener {

	private QuickAdapter<String> adapter;
	private ArrayList<String> arrays;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		if (adapter == null) {
			adapter = new QuickAdapter<String>(this, R.layout.main_item,
					initData()) {
				@Override
				protected void convert(BaseAdapterHelper helper, String item) {
					helper.setText(R.id.main_item_tv, item);
				}
			};
		}

		ListView listview = (ListView) findViewById(R.id.main_lv_contents);
		listview.setAdapter(adapter);
		listview.setOnItemClickListener(this);
	}

	public List<String> initData() {
		Resources resources = getResources();
		arrays = new ArrayList<String>();
		arrays.add(resources.getString(R.string.main_item1));
		arrays.add(resources.getString(R.string.main_item2));
		return arrays;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		String strItem = arrays.get(position);

		if (strItem.equalsIgnoreCase(getResources().getString(
				R.string.main_item1))) {
			Toast.makeText(this, strItem, Toast.LENGTH_SHORT).show();
			CustomViewActivity.launch(this);
		}

		else if (strItem.equalsIgnoreCase(getResources().getString(
				R.string.main_item2))) {
			Toast.makeText(this, strItem, Toast.LENGTH_SHORT).show();
			CustomViewActivity2.launch(this);
		}

	}

}
